<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
    $('#date').datetimepicker({
        format: "YYYY-MM-DD HH:00"
    });
    $('#date1').datetimepicker({
        format: "YYYY-MM-DD HH:00"
    });
    $('#date2').datetimepicker({
        format: "YYYY-MM-DD HH:00"
    });
    $.ajax({
        url : "${ctx}/ap/card/li",
        success : function(data) {
            $("#code1").empty();
            $("#code1").append("<option value=''>请选择</option>");
            $("#code11").empty();
            $("#code11").append("<option value=''>请选择</option>");
            $.each(JSON.parse(data), function (idx, item) {
                $("#code1").append("<option value='"+item.number+"'>"+item.number+"</option>");
                $("#code11").append("<option value='"+item.number+"'>"+item.number+"</option>");
            })
        },
        error : function(data){
            alert("操作失败!");
        }
    });
	$('#dispatchingTable').bootstrapTable({
		 
		  //请求方法
               method: 'get',
               //类型json
               dataType: "json",
               //显示刷新按钮
               showRefresh: true,
               //显示切换手机试图按钮
               showToggle: true,
               //显示 内容列下拉框
    	       showColumns: true,
    	       //显示到处按钮
    	       showExport: true,
    	       //显示切换分页按钮
    	       showPaginationSwitch: true,
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: true,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
               cache: false,    
               //是否显示分页（*）  
               pagination: true,   
                //排序方式 
               sortOrder: "asc",  
               //初始化加载第一页，默认第一页
               pageNumber:1,   
               //每页的记录行数（*）   
               pageSize: 10,  
               //可供选择的每页的行数（*）    
               pageList: [10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
               url: "${ctx}/tms/dispatching/data1",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',   
               ////查询参数,每次调用是会带上这个参数，可自定义                         
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   	edit(row.id);
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除该派车单记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/tms/dispatching/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#dispatchingTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})
                   	   
                   	});
                      
                   } 
               },
              
               onClickRow: function(row, $el){
               },
               columns: [{
		        checkbox: true
		       
		    },{
                   field: 'pro',
                   title: '项目',
                   sortable: true

               }
                   ,{
                       field: 'yfk',
                       title: '预付款',
                       sortable: true

                   }
                   ,{
                       field: 'hz',
                       title: '回执结算',
                       sortable: true

                   }
		   ,{
                       field: 'zjs',
                       title: '总件数',
                       sortable: true

                   }

                   ,{
                       field: 'zzl',
                       title: '总重量',
                       sortable: true

                   } , {
                       field: 'pcdh',
                       title: '派车单号',
                       sortable: true
                   }

                   ,{
                       field: 'hth',
                       title: '合同号',
                       sortable: true

                   },{
                       field: 'wccyddh',
                       title: '无车承运平台号',
                       sortable: true

                   }

			,{
		        field: 'cys',
		        title: '承运商',
		        sortable: true
		       
		    },{
                       field: 'skr',
                       title: '收款人',
                       sortable: true

                   }
                   ,{
                       field: 'kh',
                       title: '卡号',
                       sortable: true

                   }
                   ,{
                       field: 'khh',
                       title: '开户行',
                       sortable: true

                   },{
                       field: 'sjxm',
                       title: '司机姓名',
                       sortable: true

                   }

			,{
		        field: 'cph',
		        title: '车牌号',
		        sortable: true
		       
		    }
                   ,{
                       field: 'zyf',
                       title: '总运费',
                       sortable: true

                   }


                   ,{
                       field: 'zffs',
                       title: '支付方式',
                       sortable: true

                   } ,{
                       field: 'zffs',
                       title: '支付方式',
                       sortable: true

                   }
                   ,{
                       field: 'zhfk',
                       title: '装货付款',
                       sortable: true

                   },{
                       field: 'hdfk',
                       title: '货到付款',
                       sortable: true

                   },{
                       field: 'hzjs',
                       title: '回执结算',
                       sortable: true

                   },{
                       field: 'zhfkxj',
                       title: '装货付款现金',
                       sortable: true

                   },{
                       field: 'zhfkyk',
                       title: '装货付款油卡',
                       sortable: true

                   }
                   ,{
                       field: 'ykkh',
                       title: '油卡卡号(装货)',
                       sortable: true

                   }
                   ,{
                       field: 'hdfkxj',
                       title: '货到付款现金',
                       sortable: true

                   },{
                       field: 'hdfkyk',
                       title: '货到付款油卡',
                       sortable: true

                   }
                   ,{
                       field: 'hdykkh',
                       title: '油卡卡号(货到)',
                       sortable: true

                   }
                   ,{
                       field: 'hzfkxj',
                       title: '回执付款现金',
                       sortable: true

                   },{
                       field: 'hzfkyk',
                       title: '回执付款油卡',
                       sortable: true

                   }
                   ,{
                       field: 'hzykkh',
                       title: '油卡卡号(回执)',
                       sortable: true

                   }
                   ,{
                       field: 'zxj',
                       title: '总现金',
                       sortable: true

                   }
                   ,{
                       field: 'zyk',
                       title: '总油卡',
                       sortable: true

                   }
                   ,{
                       field: 'zyf',
                       title: '总运费',
                       sortable: true

                   }

		     ]
		
		});
		
		  
	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端

		 
		  $('#dispatchingTable').bootstrapTable("toggleView");
		}
	  
	  $('#dispatchingTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#jf').prop('disabled', $('#dispatchingTable').bootstrapTable('getSelections').length!=1);
          $('#jf1').prop('disabled', $('#dispatchingTable').bootstrapTable('getSelections').length!=1);
          $('#hz').prop('disabled', $('#dispatchingTable').bootstrapTable('getSelections').length!=1);
          $('#hz1').prop('disabled', $('#dispatchingTable').bootstrapTable('getSelections').length!=1);

      });
		  
		$("#btnImport").click(function(){
			jp.open({
			    type: 1, 
			    area: [500, 300],
			    title:"导入数据",
			    content:$("#importBox").html() ,
			    btn: ['下载模板','确定', '关闭'],
				    btn1: function(index, layero){
					  window.location='${ctx}/tms/dispatching/import/template';
				  },
			    btn2: function(index, layero){
				        var inputForm =top.$("#importForm");
				        var top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe 
				        inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
				        inputForm.onsubmit = function(){
				        	jp.loading('  正在导入，请稍等...');
				        }
				        inputForm.submit();
					    jp.close(index);
				  },
				 
				  btn3: function(index){ 
					  jp.close(index);
	    	       }
			}); 
		});
		    
	  $("#search").click("click", function() {// 绑定查询按扭
		  $('#dispatchingTable').bootstrapTable('refresh');
		});
	 
	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $("#searchForm  .select-item").html("");
		  $('#dispatchingTable').bootstrapTable('refresh');
		});
		
		
	});
		
  function getIdSelections() {
        return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }
function gethth() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hth
    });
}
function zhfkxj() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.zhfkxj
    });
}
function zhfkyk() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.zhfkyk
    });
}
function zhfk() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.zhfk
    });
}
function getcph() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.cph
    });
}
function getpcdh() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.pcdh
    });
}
function getzcxyh() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.zcxyh
    });
}
function skr() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.skr
    });
}
function kh() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.kh
    });
}
function khh() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.khh
    });
}
function getzc() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.zcfy
    });
}
function getht() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hzjs
    });
}
function gethtxj() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hzfkxj
    });
}
function gethtyk() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hzfkyk
    });
}
function getyfk() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.yfk
    });
}
function gethz() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hz
    });
}
function gethd() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hdfk
    });
}
function gethdxj() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hdfkxj
    });
}
function gethdyk() {
    return $.map($("#dispatchingTable").bootstrapTable('getSelections'), function (row) {
        return row.hdfkyk
    });
}
function yfkqr1() {
      var yfk=getyfk();
    var yfkxj=zhfkxj();
    var yfkyk=zhfkyk();
    if(yfk!="未支付"){
        return;
    }

    $("#skr1").val(skr());
    $("#kh1").val(kh());
    $("#khh1").val(khh());
    $("#yfyk").val(yfkyk);
    $("#yfxj").val(yfkxj);
    $("#yfzje").val(zhfk());

    $("#myModa2").modal("show");

}
function yfkqd() {
    $("#myModa2").modal("hide");
    jp.loading();
    jp.get("${ctx}/tms/dispatching/yfk?id=" + getIdSelections(), function(data){
        if(data.success){
            $('#dispatchingTable').bootstrapTable('refresh');
            jp.success(data.msg);
        }else{
            jp.error(data.msg);
        }
    })
}

function hzfknew() {

    var hzfk=gethz();
    if(hzfk!="未支付"){
        return;
    }
    $("#yk").val("");
    $("#xj").val("");
    $("#hdxj").val("");
    $("#remark").val("");
    $("#skr").val(skr());
    $("#kh").val(kh());
    $("#khh").val(khh());
    $("#hzht").val(getht());
    $("#hzxj").val(gethtxj());
    $("#hzyk").val(gethtyk());
    $("#hdfk").val(gethd());
    $("#hdfkxj").val(gethdxj());
    $("#hdfkyk").val(gethdyk());
    $("#myModal").modal("show");


}
function qd6() {
    var yk=$("#yk").val();
    var xj=$("#xj").val();
    var hdxj=$("#sfhdxj").val();
    var hdyk=$("#sfhdyk").val();
    var sfhz=$("#hzzje").val();
    var sfhd=$("#sfzje2").val();
    if(yk==""){
        jp.warning("油卡金额不能为空");
        return;
    }
    if(xj==""){
        jp.warning("现金金额不能为空");
        return;
    }
    if(hdyk==""){
        jp.warning("油卡金额不能为空");
        return;
    }
    if(hdxj==""){
        jp.warning("现金金额不能为空");
        return;
    }
    var remark=$("#remark").val();

    var number=$("#code1").val();
    var number1=$("#code11").val();
    jp.get("${ctx}/tms/dispatching/hzfk?id=" + getIdSelections()+"&yk="+yk+"&xj="+xj+"&number="+number+"&hdyk="+hdyk+"&hdxj="+hdxj+"&number1="+number1+"&sm="+remark, function(data){
        if(data.success){
            $("#myModal").modal("hide");
            $('#dispatchingTable').bootstrapTable('refresh');
            jp.success(data.msg);
        }else{
            jp.error(data.msg);
        }
    })


}
function hzqrnew() {
    var hzfk=gethz();
    if(hzfk!="预处理"){
        return;
    }
    $("#skr4").val(skr());
    $("#kh4").val(kh());
    $("#khh4").val(khh());
    $("#hzht4").val(getht());
    $("#hzxj4").val(gethtxj());
    $("#hzyk4").val(gethtyk());
    $("#hdfk4").val(gethd());
    $("#hdfkxj4").val(gethdxj());
    $("#hdfkyk4").val(gethdyk());
    $.ajax({
        url:"${ctx}/tms/tmsWaybill/getdetil0?i=" + getIdSelections(),
        dataType:"Json",
        success:function (data) {
            $("#yk4").val(data.oil);
            $("#xj4").val(data.money);
            $("#code4").val(data.number);
            $("#hdxj4").val(data.sfhd);
            $("#sfhdxj4").val(data.sfhdxj);
            $("#sfhdyk4").val(data.sfhdyk);
            $("#remark4").val(data.remarks);
            $("#code44").val(data.hdnumber);
            $("#sfzje4").val(data.sfzje);
        }
    })
    $("#hzqr").modal("show");
}
function qd4() {
    $("#hzqr").modal("hide");
    jp.get("${ctx}/tms/dispatching/hzqd?id=" + getIdSelections(), function(data){
        if(data.success){

            $('#dispatchingTable').bootstrapTable('refresh');
            jp.success("回执付款确定成功");
        }else{
            jp.error(data.msg);
        }
    })

}

function qx4() {
    $("#hzqr").modal("hide");
    jp.get("${ctx}/tms/dispatching/hzqx?id=" + getIdSelections(), function(data){
        if(data.success){

            $('#dispatchingTable').bootstrapTable('refresh');
            jp.success("回执款取消成功");
        }else{
            jp.error(data.msg);
        }
    })

}
</script>